#ifndef _CC_ICE_SESSION_H_
#define _CC_ICE_SESSION_H_

#include <string>
#include <map>
#include <CCRef.h>

#include <Ice/Properties.h>
#include "SessionHelper.h"
#include "Glacier2/Session.h"
#include "LuaDelegate.h"

using   std::string;

class SessionHelper;

class ConnectionInfo {
public:
	ConnectionInfo(string ip, int port, string account,
		string password,int timeout,string routerName) ;

    ConnectionInfo();

	void setProperty(const std::string& key, const std::string& value);

	std::string account;
	std::string password;
	Ice::PropertiesPtr properties;
};

class CCIceSession :
	public cocos2d::Ref,
	public SessionCallback
{
public:
	CCIceSession();
	virtual ~CCIceSession();

	static CCIceSession* create();
	bool init();

	bool connect (const ConnectionInfo& ) ;
	void disconnect ();
	
	Ice::ObjectPrx addCallback(const std::string& facet, int luaCallback);
	Ice::ObjectPrx addCallbackFacet(const std::string& name, const std::string& facet, int luaCallback);

	Ice::ObjectPrx addServant(const std::string& name, Ice::ObjectPtr servant);

	Ice::OutputStream* createOutputStream();

	bool invoke(const std::string& facet, const std::string& operation, std::vector<Ice::Byte>* params, int handler);
	
	void update(float dt);

	//////////////////// SessionCallback Imp
	virtual void createdCommunicator(SessionHelper* session);

	virtual void connected(SessionHelper* session);
	virtual void disconnected(SessionHelper* session);
	virtual void connectFailed(SessionHelper* session,const Ice::Exception& ex);

	LuaDelegate0 eventConnected;
	LuaDelegate0 eventDisconnected;
	LuaDelegate1<const Ice::Exception*> eventConnectFailed;
private:
	SessionHelper* _sessionHelper;
};

#endif /* _CC_ICE_SESSION_H_ */
